package cn.hamster3.hamsterworld.command;

import cn.hamster3.hamsterworld.core.DataManager;
import cn.hamster3.hamsterworld.core.Message;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SetSpawnCommand extends CommandBase {
    public SetSpawnCommand(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public String getPermission() {
        return "hw.setSpawn";
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        World world = player.getWorld();
        if (!player.hasPermission("hw.admin") && dataManager.getWorldData(player).getWorld() != world) {
            player.sendMessage(Message.notOwnerWorld.toString());
            return true;
        }
        world.setSpawnLocation(player.getLocation());
        player.sendMessage(Message.setSpawnLocationDone.toString());
        return true;
    }
}
